from commonDecoratorSwitch.CommonDecoratorSwitch import ADecoratorSwitch
from utils import MumberUtils
from utils.RedisUtils import RedisUtil


class WinLoseDecoratorImpl(ADecoratorSwitch):

    def switchModel(self):
        if self.BLogin.model.find("2N")!=-1:
            trendStr = ""
            for eachTrend in self.BLogin.doneData[0:8]:
                trendStr += "0" if MumberUtils.strToInt(eachTrend["LuckNum"]) % 2 == 0 else "1"

            redis = RedisUtil()
            res = redis.getHistoryLotteryInfo()
            for i in res:
                if trendStr in i:
                    self.BLogin.arr = None
                    print(f"命中了跳跃走势{i},跳过当期下注,当前号码走势{trendStr}")
                    return self.BLogin
        self.calculateIndex()
        # 切换模式
        # return self.aModelData.getModelData()

    """
        赢减输增
    """
    def calculateIndex(self):
        # 亏损
        diff = MumberUtils.strToInt(self.BLogin.eachWinSum) - MumberUtils.strToInt(self.BLogin.eachCostSum)
        if diff < 0:
            print("小于即将进入翻倍逻辑")
            self.BLogin.currentSnowballChildrenIndex = self.BLogin.currentSnowballChildrenIndex + 1
        else:
            self.BLogin.currentSnowballChildrenIndex = self.BLogin.currentSnowballChildrenIndex - 1
            if self.BLogin.currentSnowballChildrenIndex < 0:
                self.BLogin.currentSnowballChildrenIndex = 0
